<!--tvm票款差异协查-->
<template>
  <div class="TvmTicketCYXC HuikuiInfo el-card is-always-shadow el-card__body">
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      @close="closed"
      width="80%">
      <div style="line-height: 40px;background-color: #fcf7f7;padding-left: 15px">
        <span>线路：</span><span>{{getLineName(formData.lineCode)}}</span>
        <span style="margin-left: 20px">站点：</span><span>{{getStationName(formData.lineCode,formData.stationCode)}}</span>
        <span style="margin-left: 20px">TVM编号：</span><span>{{formData.tvmOrder}}</span>
        <span style="margin-left: 20px"> 收入日期：</span><span>{{formData.settleTime}}</span>
      </div>
      <avue-form :option="option" v-model="formData" @submit="handleSubmit" class="huikuiForm">

        <template slot-scope="{scope}" slot="dynamic">
          <avue-crud
            ref="TvmTicketCYXC"
            :option="listOption1"
            :data="formData.list1">
          </avue-crud>
        </template>
        <template  slot="replyReason" slot-scope="scope">
          <el-select :disabled="showType==1" v-model="formData.replyReason" placeholder="请选择" style="width: 150px">
            <el-option
              v-for="(item,index) in replyReasonList"
              :key="index"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </template>
        <template slot-scope="scope" slot="menuForm">
          <el-button type="primary" @click="closed">返回</el-button>
        </template>
      </avue-form>
    </el-dialog>
  </div>
</template>


<script>
  import {getForm, postForm} from '@/api/gen/gen'
  import ExportJsonExcel from "js-export-excel";

  import {
    clearSelect,
    electromeReasons,
    getQianxiangType,
    qianxiangType,
    selectReasons,
    fenExYuangettoFixed,
    getLineName,
    getStationName, allStatus, getSysDictItemListToDict
  } from "../../../../../../../api/subwayRat/commonCheck";
  import {
    editor_xw_SwAuTvmBoxAmountDifference,
    get_xw_SwAuTvmBoxAmountDifference,
    xw_TVMXTSJCY_cols1
  } from "../../../../../../../api/stationTiecketManager/shuJuXieChaGuanLi/TVM/XT/TVMXTSJCY/JDZYDLCK";
  export default {
    components:{
    },
    data() {
      return {
        dialogVisible:true,
        //1预览，2编辑，
        showType:1,
        listOption1:xw_TVMXTSJCY_cols1,
        formData:{
          replyReason:'',
          list1: [],
        },
        option:{},
        replyReasonList:[]
    }
    },
    created() {
      getSysDictItemListToDict({"type":"electrome_reasons"}).then((response)=>{
        this.replyReasonList = response.data.data;
      });
    },
    methods: {
      getLineName,
      getStationName,
      fenExYuangettoFixed,
      getQianxiangType,
      handleSubmit(form,done){       
        // delete param.dynamic;
	if(''==this.formData.replyReason ||this.formData.replyReason==undefined){
          this.$message.error("请选择机电专业回馈差异原因！");
	  done(false);
          return;
        }	
	if(''==this.formData.replyContent||this.formData.replyContent==undefined){
	   this.$message.error("请填写机电专业详细描述！");
          done(false);
          return;
	}
	if(this.formData.replyContent.length>500){
	   this.$message.error("字数超过限制，请修改在500字以内！");
           done(false);
          return;
	}
        let param={};
        Object.assign(param,this.formData.list1[0]);
        param.replyReason=this.formData.replyReason;
        param.replyContent=this.formData.replyContent;
        param.operatorCode=this.$store.getters.userInfo.userCode;
        param.operatorId=this.$store.getters.userInfo.userId;
        this.formatAmount(param,false);
        /*
	editor_xw_SwAuTvmBoxAmountDifference(param).then(res=>{
          if(res.data.code==0){
            this.$message.success("操作成功！");
            this.$parent.getList();
            this.closed();
          }else{
            this.$message.error("操作失败！");
          }
        });
        done();
	*/
	// 3. 发起异步请求
	editor_xw_SwAuTvmBoxAmountDifference(param).then(res => {
	    // 4. 请求完成后操作
	    if (res.data.code === 0) {
	      this.$message.success("操作成功！");
	      this.$parent.getList();
	      this.closed();
	    } else {
	      this.$message.error("操作失败！");
	    }
	  }).catch(error => {
	    // 5. 错误处理
	    this.$message.error("请求异常: " + (error.message || "未知错误"));
	  }).finally(() => {
	    done();  // 关键修复：无论成功失败都释放按钮
	  });
      },
      recallShow(id,row,showType){
        //this.listOption1.column[2].disabled = true;
        this.showType=showType;
        if(2 == this.showType){
          this.listOption1.column[2].disabled = false;
          //this.listOption1.column[5].disabled = false;
          this.listOption1.column[7].disabled = false;
          this.listOption1.column[10].disabled = false;
          this.listOption1.column[13].disabled = false;
        }else{
          this.listOption1.column[2].disabled = true;
          //this.listOption1.column[5].disabled = true;
          this.listOption1.column[7].disabled = true;
          this.listOption1.column[10].disabled = true;
          this.listOption1.column[13].disabled = true;
        }
        Object.assign(this.formData,row);
        this.getOption();
        this.formData={}
        let th=this;
        get_xw_SwAuTvmBoxAmountDifference({id:row.relationid}).then((res)=>{
          th.formData.boxUninstallStatus=res.data.data[0].boxUninstallStatus;
          th.formData.cashBoxType=res.data.data[0].cashBoxType;
          th.formData.$cellEdit=true;
          let will=JSON.parse(JSON.stringify(th.formData));
          this.formatAmount(will,true);
          th.formData.list1=[will];
          console.log(this.formData)
        }).catch((e)=>{
          this.$message.error("获取数据失败！");
        })
      },
      formatAmount(row,isYuan){
        if(isYuan){
          row.systemMoney=fenExYuangettoFixed(row,'systemMoney');
          row.tvmUnloadMoney=fenExYuangettoFixed(row,'tvmUnloadMoney');
          row.replyDsiplayMoney=fenExYuangettoFixed(row,'replyDsiplayMoney');
          row.diffUnloadDisplayMoney=fenExYuangettoFixed(row,'diffUnloadDisplayMoney');
          //row.actualMoney=fenExYuangettoFixed(row,'actualMoney');
          //row.replyActualMoney=fenExYuangettoFixed(row,'replyActualMoney');
          row.replyLoadUnloadMoney=fenExYuangettoFixed(row,'replyLoadUnloadMoney');
          row.diffLoadUnloadMoney=fenExYuangettoFixed(row,'diffLoadUnloadMoney');
          row.supplementMoney=fenExYuangettoFixed(row,'supplementMoney');
          row.replySupplementMoney=fenExYuangettoFixed(row,'replySupplementMoney');
          row.diffSupplementMoney=fenExYuangettoFixed(row,'diffSupplementMoney');
          //row.handOutMoney=fenExYuangettoFixed(row,'handOutMoney');
          row.replyHandOutMoney=fenExYuangettoFixed(row,'replyHandOutMoney');

        }else{
          row.systemMoney=Number(row.systemMoney)*100;
          row.tvmUnloadMoney=Number(row.tvmUnloadMoney)*100;
          row.replyDsiplayMoney=Number(row.replyDsiplayMoney)*100;
          row.diffUnloadDisplayMoney=Number(row.diffUnloadDisplayMoney)*100;
          //row.actualMoney=Number(row.actualMoney)*100;
          //row.replyActualMoney=Number(row.replyActualMoney)*100;
          row.replyLoadUnloadMoney=Number(row.replyLoadUnloadMoney)*100;
          row.diffLoadUnloadMoney=Number(row.diffLoadUnloadMoney)*100;
          row.supplementMoney=Number(row.supplementMoney)*100;
          row.replySupplementMoney=Number(row.replySupplementMoney)*100;
          row.diffSupplementMoney=Number(row.diffSupplementMoney)*100;
          //row.handOutMoney=Number(row.handOutMoney)*100;
          row.replyHandOutMoney=Number(row.replyHandOutMoney)*100;
        }
      },
      closed(){
        this.dialogVisible=false;
        this.$parent.isShowDia=false;
      },
      getOption(){
        this.option={
          submitBtn:this.showType == 2,
          emptyBtn:false,
          submitText:'确认',
          // emptyText:'返回',
          group:[
            {
              icon:'',
              sortable:true,
              label: '钱箱操作信息回馈',
              // collapse:false,
              prop: 'group1',
              indexLabel:"#",
              column: [{
                label: '',
                prop: 'dynamic',
                span:24,
                formslot:true
              }
              ]
            },
            {
              label: '原因与备注',
              // collapse:false,
              prop: 'group3',
              column: [{
                label: '机电专业回馈差异原因',
                prop: 'replyReason',
                // formslot : true,
                labelWidth:130,
                disabled: this.showType==1,
                type:'select',
                dicData:electromeReasons(),
              },
                {
                  label: '车站回馈差异原因',
                  prop: 'kyReplyReason',
                  labelWidth:130,
                  disabled: true,
                  type:'select',
                  dicData:electromeReasons(),
                },
                {
                  label: '机电专业详细描述',
                  prop: 'replyContent',
                  type: 'textarea',
                  labelWidth:130,
                  disabled: this.showType==1
                },
                {
                  label: '车站详细描述',
                  prop: 'kyReplayConent',
                  type: 'textarea',
                  labelWidth:130,
                  disabled: true
                },
                {
                  label: '车站备注',
                  prop: 'stationCleanRemark',
                  type: 'textarea',
                  labelWidth:130,
                  disabled:true
                }
              ]
            }
          ]
        };
        this.isReload=false;
        this.$nextTick(()=>{
          this.isReload=true;
        })
      }
    },
    mounted() {

    }
  }
</script>
<style lang="scss">
  .TvmTicketCYXC.HuikuiInfo{
    .avue-group[index='3']{
      .el-form-item{
        min-width: 450px;
      }
      .avue-form__row{
        width: 70%;
      }
    }
  }
</style>
